package org.endy.leisure.diaTracker.controller

import io.swagger.v3.oas.annotations.media.Schema
import org.jetbrains.annotations.NotNull
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import java.util.*

/**
 * 定义公共响应结构
 */
@Schema(description = "公共响应结构")
data class WebResponse<T>(
    @Schema(description = "响应编码") var code: Int = 200,
    @Schema(description = "响应消息") var message: String = "success",
    @Schema(description = "响应数据") var data: T? = null
) {
    companion object {
        /**
         * 成功消息封装
         */
        fun <T> success(data: T?): WebResponse<T> {
            return WebResponse(data = data)
        }

        /**
         * 失败消息封装
         */
        fun <T> fail(msg: String, code: Int = 500): WebResponse<T> {
            return WebResponse(code = code, message = msg)
        }
    }
}

/**
 * Flux结果转换为标准输出
 */
fun <T> Flux<T>.toResponse(): Mono<WebResponse<List<T>>> = collectList().map {
    WebResponse(data = it)
}

/**
 * Mono结果转换为标准输出
 */
fun <T> Mono<T>.toResponse(): Mono<WebResponse<T>> = map {
    WebResponse(data = it)
}

/**
 * index测试请求
 */
@Schema(description = "index请求")
data class IndexRequest(@Schema(description = "请求名称", example = "张三") val name: String)

@Schema(description = "index响应")
data class IndexResponse(
    @Schema(description = "响应字段")
    val name: String,
    @Schema(description = "响应时间", example = "2025-06-08 23:41:53")
    val requestTime: Date = Date()
)

//用户注册实体
@Schema(description = "用户请求实体")
data class UserRegisterRequest(
//    @Schema(description = "微信唯一ID", example = "1234554321")
//    val openId: String? = null,
    @Schema(description = "手机号", example = "15810854756")
    val phone: String? = null,
    @Schema(description = "昵称", example = "张三")
    val nickname: String? = null,
    @Schema(description = "登录密码")
    val password: String? = null
)

//用户注册实体
@Schema(description = "用户变更实体")
data class UserUpdateRequest(
    @Schema(description = "用户ID", example = "1234554321")
    val userId: Long,
    @Schema(description = "登录密码")
    val password: String? = null,

    @Schema(description = "用户昵称")
    var nickname: String? = null, // 用户昵称

    @Schema(description = "图像")
    var avatar: String? = null, // 用户头像

    @Schema(description = "用户类型", example = "用户类型：user、doctor、admin")
    val roleType: String = "user",// 用户类型：user、doctor、admin

)

// 用户角色变更实体
@Schema(description = "用户角色更新实体")
data class ChangeUserRoleRequest(
    @Schema(description = "用户的手机号码")
    val phone: String,
    @Schema(description = "用户类型", example = "用户类型：user、doctor、admin")
    val roleType: String = "user",// 用户类型：user、doctor、admin
)

// 用户请求实体
@Schema(description = "用户请求实体")
data class UserIdRequest(@Schema(description = "用户ID", example = "1234554321") val userId: Long)


// 用户提问
@Schema(description = "用户提问实体")
data class QuestionRequest(
    @Schema(description = "提问内容", example = "最近心率很快，可能是什么原因")
    val content: String,
    @Schema(description = "用户ID")
    @NotNull
    val userId: Long,
    @Schema(description = "问题相关图片", example = "[\"......\",\"......\"]")
    val images: List<String>? = null,
)

@Schema(description = "问题回答实体")
data class AnswerQuestionRequest(
    @Schema(description = "问题ID")
    val id: Long,
    @Schema(description = "回答内容", example = "可能是没有休息好")
    val content: String,
    @Schema(description = "用户ID")
    val userId: Long,
)

@Schema(description = "公告发布实体")
data class AnnouncementRequest(
    @Schema(description = "公告标题", example = "人员变更")
    val title: String,
    @Schema(description = "公告内容")
    val content: String,
    @Schema(description = "公告类型")
    val type: String,
    @Schema(description = "发布人职位", example = "护士长")
    val publisher: String,
    @Schema(description = "公告图片的base64字符串", example = "......")
    val image: String? = null,
    @Schema(description = "过期时间", example = "2025-06-26 00:00:00")
    val expireTime: Date? = null,
    @Schema(description = "用户的唯一ID")
    val userId: Long
)

@Schema(description = "公告查看实体")
data class AnnouncementViewRequest(
    @Schema(description = "用户的唯一ID")
    val userId: Long,
    @Schema(description = "公告IDID")
    val announcementId: Long
)

@Schema(description = "试卷答题实体")
data class ExamAnswerRequest(
    @Schema(description = "试卷ID")
    val examId: Long,
    @Schema(description = "用户ID")
    val userId: Long,
    @Schema(description = "试卷答题", example = "a,b,c,f,a")
    val answer: String
)
